package com.csu.cphone.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.csu.common.exception.WebException;
import com.csu.common.vo.ResultVo;
import com.csu.cphone.pojo.StorePojo;
import com.csu.cphone.service.StoreService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
 * @项目名称：cphone
 * @类名称：StoreController
 * @类描述：
 * @创建人：Tangc
 * @创建时间：2017年9月12日 下午2:10:07
 * @company:
 */
@Controller
@RequestMapping("/storeinfo")
@Api(value = "store", description = "基础信息")
public class StoreController
{

    @Autowired
    private StoreService storeService;

    @ResponseBody
    @ApiOperation(value = "根据producerId查询门店信息", notes = "返回服务商的门店信息")
    @RequestMapping(value = "getByProducerId/{producerId}", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<StorePojo> getByProducerId(HttpServletRequest request,
            @ApiParam(value = "producerId") @PathVariable(value = "producerId") Integer producerId) throws WebException
    {
        ResultVo<StorePojo> result = new ResultVo<StorePojo>();
        StorePojo store = storeService.getByProducerId(producerId);

        result.setData(store);
        return result;

    }

    @ResponseBody
    @ApiOperation(value = "根据producerId更新门店信息", notes = "根据producerId更新门店信息")
    @RequestMapping(value = "updateByProducerId", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/json; charset=utf-8" })
    public ResultVo<Integer> updateByProducerId(HttpServletRequest request, @RequestBody StorePojo store)
            throws WebException
    {
        ResultVo<Integer> result = new ResultVo<Integer>();
        Integer update = storeService.updateByProducerId(store);
        result.setData(update);
        return result;

    }
}
